package com.hzb.LNReader;

import java.io.File;
import java.io.Serializable;

public class ReaderRecord implements Serializable {
	private static final long serialVersionUID = 9067652786901008102L;
	
	public ReaderRecord prev, next;
	
	public File file;
	public int scrollOffset;
	public int fileOffset;
	public int startLineSeq;
	public String encoding = "UTF-8";
	public long lastReadTime;
	public int maxLineSeq = Integer.MAX_VALUE;
	public String summary;
	public int process;
	public int fileSize;
	
	public void offer() {
		if (prev == null) return;
		else prev.next = next;
		
		if (next != null) next.prev = prev;
		
		next = ReaderHistory.head;
		ReaderHistory.head.prev = this;
		ReaderHistory.head = this;
		prev = null;
	}
	
	public void reset() {
		fileOffset = scrollOffset = 0;
		maxLineSeq = Integer.MAX_VALUE;
		process = 0;
		startLineSeq = 0;
		lastReadTime = System.currentTimeMillis();
		fileSize = (int) file.length();
		summary = "";
	}
	
	public ReaderRecord() {
	}
	
	public ReaderRecord(File file) {
		this.file = file;
		this.fileSize = (int) file.length();
		reset();
		
		if (ReaderHistory.head == null) {
			ReaderHistory.head = this;
		} else {
			ReaderHistory.head.prev = this;
			next = ReaderHistory.head;
			ReaderHistory.head = this;
		}
	}
	
	public void remove() {
		if (prev != null) prev.next = next;
		else ReaderHistory.head = next;
		if (next != null) next.prev = prev;
	}
}
